package kr.hkit.androidcomplete03.ETC;

import java.util.ArrayList;

import kr.hkit.androidcomplete03.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

public class ListViewEditEx extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.listviewplus);
		
		final ArrayList<String> midList = new ArrayList<String>();
		ListView list = (ListView) findViewById(R.id.pluslistview);
		
		final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, midList);
		list.setAdapter(adapter);
		
		final EditText editItem = (EditText) findViewById(R.id.pluset);
		Button btnadd = (Button) findViewById(R.id.editplus);
		
		btnadd.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				midList.add(editItem.getText().toString());
				adapter.notifyDataSetChanged();
			}
			
		});
		
		list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

			@Override
			public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
				midList.remove(arg2);
				adapter.notifyDataSetChanged();
				Toast.makeText(getApplicationContext(), midList.get(arg2) + "삭제됐네", 0).show();
				return false;
			}
			
		});
		

	}
}
